package aliyun_api

import "errors"

type Zidv2VerifyIdcardv struct {
	ErrorCode int    `json:"error_code"`
	Reason    string `json:"reason"`
	Result    struct {
		RealName string `json:"realname"`
		IdCard   string `json:"idcard"`
		IsOk     bool   `json:"isok"`
	}
}

func (client *Client) VerifyIdCard(authInfo AuthInfo, idCard string, name string) (*Zidv2VerifyIdcardv, error) {
	var result Zidv2VerifyIdcardv
	if err := client.get(&authInfo, "https://zid.market.alicloudapi.com/idcard/VerifyIdcardv2", map[string]string{
		"cardNo":   idCard,
		"realName": name,
	}, &result); err != nil {
		return nil, err
	}
	if result.ErrorCode > 0 {
		return &result, errors.New(result.Reason)
	}
	return &result, nil
}

type Zidv2VerifyIdcardv2 struct {
	ErrorCode int    `json:"error_code"`
	Reason    string `json:"reason"`
	Result    struct {
		RealName string `json:"realname"`
		IdCard   string `json:"idcard"`
		IsOk     bool   `json:"isok"`
	}
}

func (client *Client) VerifyIdCard2(authInfo AuthInfo, idCard string, name string) (*Zidv2VerifyIdcardv2, error) {
	var result Zidv2VerifyIdcardv2
	if err := client.get(&authInfo, "https://zidv2.market.alicloudapi.com/idcard/VerifyIdcardv2", map[string]string{
		"cardNo":   idCard,
		"realName": name,
	}, &result); err != nil {
		return nil, err
	}
	if result.ErrorCode > 0 {
		return &result, errors.New(result.Reason)
	}
	return &result, nil
}
